# encoding: utf-8

from app.extensions import log
from flask_restplus import Resource
from app.extensions.api import Namespace
from app.modules.common.utils import checkToken
from . import parameters, schemas
from .models import LoadLevel

api = Namespace('load_level', description = "负载级别")  # pylint: disable=invalid-name


@api.route('/')
class LoadLevelList(Resource):
    @api.parameters(parameters.LoadLevelListParameters())
    @api.response(schemas.LoadLevelListSchema(many = False))
    @checkToken
    def get(self, args, **kwargs):
        """
        查询负载级别列表
        :param args:
        :return:
        """
        log.info("============== start query load-level list ==============")
        _level_id = args['level_id']
        log.info("============== level_id is %s ==============" % _level_id)
        _list = []
        if _level_id is None:
            _list = LoadLevel.query.all()
        else:
            _list = LoadLevel.query.filter_by(id = _level_id).all()
        return {'success': True, 'msg': '', 'data': _list}
